package nl.hanze.designpatterns.mvc.model;

import java.util.HashMap;
import java.util.Map;

import javax.swing.text.html.HTMLDocument.Iterator;

import nl.hanze.designpatterns.mvc.view.View;

public abstract class Model {
	
	private Map<String, View> views;
	
	protected Model(){
		views = new HashMap<String, View>();
	}
	
	/**
	 * Add a View to this model
	 * @param id
	 * @param view
	 */
	public void addView(String id, View view){
		this.views.put(id, view);
	}
	
	/**
	 * Get a View from this model
	 * @param id
	 * @return
	 */
	public View getView(String id){
		return this.views.get(id);
	}
	
	/**
	 * Remove a View from this model
	 * @param id
	 */
	public void removeView(String id){
		this.views.remove(id);
	}
	
	/**
	 * Notify all associated views that this model has changed so they can update themselves
	 */
	public void notifyViews(){
		System.out.println("[INFO] notify all views " + this.views.size());
		for(View v : this.views.values()){
			System.out.println("test");
			v.notifyChange();
		}
	}
	
}
